Skip to content

feat: appeal command#233

Merged
cristiam86 merged 7 commits into
mainfrom
dxp-173-appeal-command
Jul 9, 2025
Merged

feat: appeal command#233
cristiam86 merged 7 commits into
mainfrom
dxp-173-appeal-command

Conversation

@epsjunior

@epsjunior epsjunior commented Jul 7, 2025

Copy link
Copy Markdown
Contributor

Add Appeal Transaction Command

Summary

Implements a new appeal command that allows users to appeal transactions by their hash. The command follows the established CLI architecture pattern and includes comprehensive test coverage.

Changes

🚀 New Features

  • Appeal Command: New appeal <txId> command to appeal transactions
  • Transactions Command Category: Created new src/commands/transactions/ folder structure
  • RPC Support: Optional --rpc parameter for custom network endpoints

🏗️ Implementation Details

  • Action Class: AppealAction extends BaseAction following established patterns
  • Client Integration: Calls client.appealTransaction() and waits for transaction receipt
  • User Feedback: Uses spinner UI for progress indication and result display
  • Error Handling: Comprehensive error handling with user-friendly messages

📁 File Structure

src/commands/transactions/
├── appeal.ts           # AppealAction class implementation
└── index.ts           # Command registration and CLI setup

🧪 Testing

  • Action Tests (tests/actions/appeal.test.ts):

    • Success scenarios with transaction receipt
    • Error handling and failure cases
    • Custom RPC URL functionality
    • Client initialization verification
  • Command Tests (tests/commands/appeal.test.ts):

    • CLI argument parsing
    • Command instantiation
    • Option validation
    • Error handling for invalid options

🔧 Usage

# Appeal a transaction
appeal 0x1234567890123456789012345678901234567890123456789012345678901234

# Appeal with custom RPC
appeal 0x1234567890123456789012345678901234567890123456789012345678901234 --rpc https://custom-rpc.com

✨ Code Quality

  • Follows existing TypeScript patterns and interfaces
  • Uses proper type safety with TransactionHash type
  • Consistent error handling and user feedback
  • DRY principle applied with test constants
  • Comprehensive test coverage for both happy and error paths

🔗 Dependencies

  • Integrates with existing genlayer-js client
  • Uses established BaseAction infrastructure
  • Compatible with current CLI command structure

Testing: ✅ All tests pass
Type Safety: ✅ Full TypeScript coverage
Documentation: ✅ Inline code documentation
Architecture: ✅ Follows established patterns

Summary by CodeRabbit

  • New Features

    • Added a new CLI command to appeal a transaction by providing its transaction hash, with optional support for specifying a custom RPC endpoint.
  • Tests

    • Introduced comprehensive tests for the new appeal functionality and command-line interface to ensure correct behavior and error handling.

@epsjunior epsjunior requested a review from cristiam86 July 7, 2025 14:35
@coderabbitai

coderabbitai Bot commented Jul 7, 2025

Copy link
Copy Markdown

Walkthrough

A new "appeal" transaction command is introduced into the CLI, allowing users to appeal a transaction by its hash with optional RPC endpoint specification. Supporting logic, command registration, and comprehensive tests for both the action and command interface have been added, along with necessary integration into the CLI initialization.

Changes

File(s) Change Summary
src/commands/transactions/appeal.ts Added AppealAction class and AppealOptions interface to handle transaction appeal logic.
src/commands/transactions/index.ts Introduced initializeTransactionsCommands to register the "appeal" subcommand in the CLI.
src/index.ts Integrated transaction commands initialization into overall CLI setup.
tests/actions/appeal.test.ts Added unit tests for AppealAction covering success, error, and custom RPC scenarios.
tests/commands/appeal.test.ts Added tests for CLI "appeal" command parsing and argument handling.
tests/index.test.ts Mocked transaction command initialization for CLI tests.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant AppealAction
    participant Client
    participant Spinner

    User->>CLI: Run "appeal <txId> [--rpc]"
    CLI->>AppealAction: appeal({ txId, rpc })
    AppealAction->>Client: getClient(rpc)
    AppealAction->>Client: initializeConsensusSmartContract()
    AppealAction->>Spinner: start("Appealing transaction...")
    AppealAction->>Client: appealTransaction(txId)
    AppealAction->>Client: waitForReceipt(txId, retries)
    alt Success
        AppealAction->>Spinner: succeed(result)
    else Error
        AppealAction->>Spinner: fail(error)
    end
Loading

Poem

A bunny appeals with a hop and a spin,
Now transactions can plead, let the justice begin!
With tests all around and commands in a row,
The CLI’s smarter—just watch it go!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-07T14_36_58_247Z-debug-0.log

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/commands/transactions/appeal.ts (2)

4-6: Consider removing the unused interface or refactor method parameters.

The AppealOptions interface is defined but never used in this file. Either remove it if not needed, or refactor the method parameters to use it for better type consistency.

If you intend to use this interface, apply this diff to improve type safety:

  async appeal({
    txId,
    rpc,
  }: {
    txId: TransactionHash;
-   rpc?: string;
+   options?: AppealOptions;
  }): Promise<void> {
-   const client = await this.getClient(rpc);
+   const client = await this.getClient(options?.rpc);

Or simply remove the unused interface:

-export interface AppealOptions {
-  rpc?: string;
-}

9-11: Remove the unnecessary constructor.

The constructor only calls super() with no additional logic, making it redundant. TypeScript will automatically call the parent constructor.

Apply this diff to remove the unnecessary constructor:

-  constructor() {
-    super();
-  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a17392f and 1510747.

📒 Files selected for processing (6)
  • src/commands/transactions/appeal.ts (1 hunks)
  • src/commands/transactions/index.ts (1 hunks)
  • src/index.ts (2 hunks)
  • tests/actions/appeal.test.ts (1 hunks)
  • tests/commands/appeal.test.ts (1 hunks)
  • tests/index.test.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (5)
tests/actions/appeal.test.ts (1)
src/commands/transactions/appeal.ts (1)
  • AppealAction (8-39)
tests/commands/appeal.test.ts (2)
src/commands/transactions/index.ts (1)
  • initializeTransactionsCommands (5-16)
src/commands/transactions/appeal.ts (1)
  • AppealAction (8-39)
src/commands/transactions/index.ts (1)
src/commands/transactions/appeal.ts (2)
  • AppealOptions (4-6)
  • AppealAction (8-39)
src/index.ts (1)
src/commands/transactions/index.ts (1)
  • initializeTransactionsCommands (5-16)
src/commands/transactions/appeal.ts (1)
src/lib/actions/BaseAction.ts (1)
  • BaseAction (11-117)
🪛 Biome (1.9.4)
src/commands/transactions/appeal.ts

[error] 9-11: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

🔇 Additional comments (16)
tests/index.test.ts (1)

44-46: LGTM: Mock follows established pattern.

The mock for the transactions commands module is consistent with the existing mocking pattern and properly supports testing of the CLI initialization.

src/index.ts (2)

13-13: LGTM: Clean integration following established pattern.

The import follows the same pattern as other command module imports.


25-25: LGTM: Proper command initialization.

The function call is correctly placed in the initialization sequence and follows the established pattern.

tests/commands/appeal.test.ts (4)

1-21: LGTM: Well-structured test setup.

The test suite setup is comprehensive with proper imports, mocking, and cleanup. The mock transaction ID format is appropriate for testing transaction hash inputs.


22-28: LGTM: Default options test is thorough.

The test correctly verifies that AppealAction is instantiated and its appeal method is called with the expected parameters.


30-44: LGTM: Custom RPC test covers important functionality.

The test properly verifies that custom RPC URLs are passed through correctly to the AppealAction.


51-57: LGTM: Error handling test uses correct approach.

The use of exitOverride() is the proper way to test commander error handling without causing the test process to exit.

src/commands/transactions/index.ts (2)

1-3: LGTM: Proper imports and type usage.

The imports are clean and use appropriate TypeScript types from genlayer-js.


5-16: LGTM: Well-implemented command registration.

The command definition is clear and follows CLI best practices:

  • Required transaction ID argument with proper typing
  • Optional RPC flag for flexibility
  • Clean action implementation with proper instantiation and method call
  • Consistent return pattern
tests/actions/appeal.test.ts (5)

1-34: LGTM: Excellent test setup with proper mocking.

The test setup is comprehensive with appropriate mocking of external dependencies and internal methods. The mock structure properly isolates the unit under test.


35-51: LGTM: Thorough success scenario test.

The test properly verifies the appeal transaction flow and confirms that success feedback is provided correctly.


53-62: LGTM: Comprehensive error handling test.

The test correctly verifies that errors are caught and appropriate failure feedback is provided.


64-87: LGTM: Custom RPC functionality well tested.

The test properly verifies that custom RPC URLs are passed to the client creation and the appeal operation executes correctly.


89-98: LGTM: Consensus contract initialization properly tested.

The test ensures that the consensus smart contract is initialized before performing the appeal operation, which is a critical requirement.

src/commands/transactions/appeal.ts (2)

1-2: LGTM - Clean imports with proper typing.

The imports correctly use the TransactionHash type from genlayer-js and extend the established BaseAction pattern.


13-38: Well-implemented appeal method with proper error handling.

The method implementation follows established patterns from BaseAction:

  • Properly uses getClient() with optional RPC parameter
  • Initializes consensus smart contract before operation
  • Uses spinner for user feedback
  • Implements comprehensive error handling
  • Follows the async/await pattern consistently

The retry configuration (100 retries, 5-second intervals) provides reasonable defaults for transaction confirmation.

@cristiam86 cristiam86 merged commit a33f882 into main Jul 9, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants